# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool

def isBadVersion(version):
    if version < 4:
        return True
    return False


class Solution:
    def firstBadVersion(self, n):
        num, min_num, max_num = 0, 0, n
        while max_num - min_num > 1:
            if not isBadVersion(num):
                num, min_num = (num + max_num) // 2, num
            else:
                num, max_num = (num + min_num) // 2, num
        return max_num


a = Solution()
print(a.firstBadVersion(5))
